/*Nguyen Truong Minh Chanh
photo_thinhan@yahoo.com*/
setCal()
function leapYear(year) {
if (year % 4 == 0) 
return true 
}
function getDays(month, year) {
var ar = new Array(12)
ar[0] = 31
ar[1] = (leapYear(year)) ? 29 : 28 
ar[2] = 31 
ar[3] = 30 
ar[4] = 31 
ar[5] = 30 
ar[6] = 31 
ar[7] = 31 
ar[8] = 30 
ar[9] = 31 
ar[10] = 30 
ar[11] = 31 
return ar[month]
}
function getMonthName(month) {
var ar = new Array(12)
ar[0] = "Tháng 1"
ar[1] = "Tháng 2"
ar[2] = "Tháng 3"
ar[3] = "Tháng 4"
ar[4] = "Tháng 5"
ar[5] = "Tháng 6"
ar[6] = "Tháng 7"
ar[7] = "Tháng 8"
ar[8] = "Tháng 9"
ar[9] = "Tháng 10"
ar[10] = "Tháng 11"
ar[11] = "Tháng 12"
return ar[month]
}
function setCal() {
var now = new Date()
var year = now.getYear()
if (year < 1000)
year+=1900
var month = now.getMonth()
var monthName = getMonthName(month)
var date = now.getDate()
var thu = now.getDay()
now = null
var firstDayInstance = new Date(year, month, 1)
var firstDay = firstDayInstance.getDay()
firstDayInstance = null
var days = getDays(month, year)
var last=month-1
var lastyear=year
if(last==0){
	last=12
	lastyear=year-1
}
var dayss = getDays(last, lastyear)
drawCal(firstDay + 1, days, dayss, date, monthName, year, thu)
}
function drawCal(firstDay, lastDate, lastDate1, date, monthName, year, thu) {

var text = "" 
text += '<CENTER>'
text += '<TABLE BORDER=0 align="center" CELLSPACING=0 CELLPADDING=0 bgcolor=#FFFFCC style="BORDER: #80b5d7 1px solid;" >' 
text += '<TH COLSPAN=7 HEIGHT=30 style="BORDER-RIGHT: #80b5d7 1px solid; BORDER-BOTTOM: #80b5d7 1px solid;">' 
text += '<FONT COLOR="midnightblue" style="font-size:16px">' 
text += monthName + ' - ' + year 
text += '</FONT>' 
text += '</TH>' 
var weekDay = new Array(7)
weekDay[0] = "CN"
weekDay[1] = "T2"
weekDay[2] = "T3"
weekDay[3] = "T4"
weekDay[4] = "T5"
weekDay[5] = "T6"
weekDay[6] = "T7"
text += '<TR ALIGN="center" VALIGN="center">'
for (var dayNum = 0; dayNum < 7; ++dayNum) {
if (dayNum == thu) {
text += '<TD WIDTH=24 HEIGHT=25 style="BORDER-RIGHT: #80b5d7 1px solid; BORDER-BOTTOM: #80b5d7 1px solid;">'
text += '<FONT COLOR="red"><b>'
text += weekDay[dayNum]
text += '</FONT></b>'
text += '</TD>'
} else
text += '<TD WIDTH=24 HEIGHT=25 style="BORDER-RIGHT: #80b5d7 1px solid; BORDER-BOTTOM: #80b5d7 1px solid;"><b>' + weekDay[dayNum] + '</b></TD>' 
}
text += '</TR>'
var digit = 1
var di = 1
var curCell = 1
var diti = lastDate1-firstDay+2
var sodong=6
if(firstDay==1){
text += '<TR ALIGN="left" VALIGN="top">'
var diti = lastDate1-6
for (var col = 1; col <= 7; ++col) {
text += '<TD HEIGHT=25 style="BORDER-RIGHT: #80b5d7 1px solid; BORDER-BOTTOM: #80b5d7 1px solid;color:#cccccc">' + diti + '</TD>';
diti++
} 
var sodong=5
text += '</TR>'
}
for (var row = 1; row <= sodong; ++row) {
text += '<TR ALIGN="left" VALIGN="top">'
for (var col = 1; col <= 7; ++col) {
if (curCell < firstDay) {
text += '<TD HEIGHT=25 style="BORDER-RIGHT: #80b5d7 1px solid; BORDER-BOTTOM: #80b5d7 1px solid;color:#cccccc">' + diti + '</TD>';
curCell++
diti++
} else {
if (digit == date) { 
text += '<TD HEIGHT=25 style="BORDER-RIGHT: #80b5d7 1px solid; BORDER-BOTTOM: #80b5d7 1px solid;">'
text += '<FONT COLOR="red">'
text += digit
text += '</FONT>'
text += '</TD>'
} else{
	if(digit > lastDate){
      text += '<TD HEIGHT=25 style="BORDER-RIGHT: #80b5d7 1px solid; BORDER-BOTTOM: #80b5d7 1px solid; color:#cccccc">' + di + '</TD>'
	  di++
	}else{
	  text += '<TD HEIGHT=25 style="BORDER-RIGHT: #80b5d7 1px solid; BORDER-BOTTOM: #80b5d7 1px solid;">' + digit + '</TD>'
	}
}
digit++
}
}
text += '</TR>'
}
text += '</TABLE>'
text += '</CENTER>'
document.write(text) 
}